/**
 * create by young (young2f@outlook.com) on 2023/4/22
 */
'use strict';
import moment from 'moment';
import {Button, Form, Input, notification, Select} from 'antd';
import ComponentBase from '../../components/Base/ComponentBase';
import {FormField, FormLayout, ModalFooter} from 'antd-extra';
import notify from '../../components/NotificationExtra';
import React from 'react';
import {connect} from 'dva';

import Upload from 'antd/es/upload';

const {TextArea} = Input;

moment.locale('zh-cn');
@Form.create()
@connect(({global, user, device}) => ({...global, ...user, ...device}))
export default class ModalJsonInfo extends ComponentBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {

  }

  renderFoot = () => {
    const {foot, value, update, modalRef, result} = this.props;
    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };
  //  handleChange = ({ file, fileList }) => {
  //   try {
  //     const { status, response } = file;
  //     // 刚才的子定义属性，是否是Excel文件，通过校验
  //     if (!file.isExcel) {
  //       return;
  //     }
  //     // 只能上传一个文件,不能用flie直接设置，onRemove函数会触发handleChange
  //     setFileList(fileList.slice(-1));
  //     if (status === 'error') {
  //       throw new Error('上传失败');
  //     }
  //     if (status === 'done' && response) {
  //       const { code } = response;
  //       // ...
  //     }
  //   } catch (e) {
  //     message.error(e.message);
  //   }
  // };
  // // 这里是只有一个文件，移除即清空文件列表
  // const handleReset = () => {
  //   setFileList([]);
  // };
  // // 点击提交，formData的形式传参
  //  handleSubmit = async () => {
  //   try {
  //     const formData = new FormData();
  //     formData.append('file', fileList[0].originFileObj);
  //     const res = await submitBatchFile(formData);
  //     const { code } = res;
  //     if (code !== '000000') {
  //       throw new Error('提交失败');
  //     }
  //     message.success('提交成功');
  //   } catch (e) {
  //     console.error(e);
  //     message.error(e.message);
  //   }
  // };

  render() {
    const {json} = this.props;
    return (
      <div>
        <Upload
          beforeUpload={file => {
            const {name} = file;
            // 校验是否是excel文件
            const isExcel = /(xls|xlsx)$/i.test(name);
            if (!isExcel) {
              notify({type: 'error', message: '文件不是excel类型'});
            }
            // 自定义属性
            file.isExcel = isExcel;
            return isExcel;
          }}
          onChange={file => {
            console.log('on change ', file);
          }}
        >
          <Button >上传附件</Button>
        </Upload>
        {this.renderFoot()}
      </div>
    );
  }
}
